/* 
 * frm-layout-2.0.js
 * @since 1.0 <2015-6-19> SoChishun Added.
 */
function layout_init() {
    $('.main-nav-sub').menu({onClick: function (item) {
            add_nav_tabs(item);
            return false;

        }});
    $('#mm_help').menu({onClick: function (item) {
            if ('lnk_info' == item.name) {
                curd_grid.lnk_info_event('<a href="' + $(item.target).data('href') + '">' + item.text + '</a>');
            }
        }});
    $('#user_bar').delegate('.lnk_grid_add', 'click', function () {
        return curd_grid.lnk_add_event(this);
    })
    setInterval('clock()', 1000);
}

/**
 * 添加导航标签
 * @param {type} menu
 * @since 1.0 <2015-9-10> SoChishun Added.
 */
function add_nav_tabs(menu) {
    var tab_id = '#tab_main';
    var scontent = '<iframe frameborder="0" scrolling="yes" style="width:100%" src="' + $(menu.target).data('href') + '" onload="$(this).height(get_window_height(130))"></iframe>';
    $(tab_id).tabs('add', {
        title: menu.text,
        content: scontent,
        closable: true,
        tools: [{
                iconCls: 'icon-mini-refresh',
                handler: function () {
                    var ifrm = $(tab_id).tabs('getSelected').find('iframe');
                    var src = ifrm.attr('src');
                    ifrm.attr('src', "about:blank").attr('src', src);
                }
            }],
    });

}
/**
 * 获取主容器高度
 * @returns Number
 * @since 1.0 2014-8-12 by sutroon
 */
function get_window_height(offset){
    if (undefined==offset) {
        offset = 100;
    }
    var winHeight = 0;
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
    }
    return winHeight - offset;
    
}

/**
 * 时钟功能
 * @returns {void}
 * @since 1.0 2014-8-15 by sutroon
 */
function clock() {
    var date = new Date();
    var arrdate = [date.getHours(), date.getMinutes(), date.getSeconds()];
    var text = ((arrdate[0] < 10 ? '0' + arrdate[0] : arrdate[0]) + ':' + (arrdate[1] < 10 ? '0' + arrdate[1] : arrdate[1]) + ':' + (arrdate[2] < 10 ? '0' + arrdate[2] : arrdate[2]));
    var h = date.getHours();
    var w = '';
    if (h < 5) {
        w = '凌晨了,注意身体,早点休息哦!';
    } else if (h >= 5 && h < 11) {
        w = '早上好,一日之计在于晨,加油哦^_^';
    } else if (h > 14 && h < 18) {
        w = '下午好,保持愉快心情努力工作哦~';
    } else if (h > 18 && h < 21) {
        w = '晚上好!';
    } else if (h >= 21 && h < 24) {
        w = '夜深了,还没休息啊!';
    }
    var d2 = new Date();
    d2.setMonth(0);
    d2.setDate(1);
    var rq = date - d2;
    var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000));
    var s2 = Math.ceil(s1 / 7) + 1;
    var week = ['日', '一', '二', '三', '四', '五', '六'];
    var title = (date.getMonth() + 1) + '月' + date.getDate() + '日 星期' + week[date.getDay()] + ' 第' + s1 + '天/' + s2 + "周";
    $('#head-clock').attr('title', title).text(text);
}